import axios from 'axios';

const API_BASE_URL = '/api/administrator'; // 使用代理路径

export const userListService = async (params) => {
    try {
        const response = await axios.get(`${API_BASE_URL}/userpage`, { params });
        return response.data;
    } catch (error) {
        throw new Error('Error fetching user list');
    }
};

export const addUserService = async (user) => {
    try {
        const response = await axios.post(`${API_BASE_URL}/adduser`, user);
        return response.data;
    } catch (error) {
        throw new Error('Error adding user');
    }
};

export const updateUserService = async (user) => {
    try {
        const response = await axios.put(`${API_BASE_URL}/updateuser`, user);
        return response.data;
    } catch (error) {
        throw new Error('Error updating user');
    }
};

export const deleteUserService = async (id) => {
    try {
        const response = await axios.delete(`${API_BASE_URL}/deleteuser/${id}`);
        return response.data;
    } catch (error) {
        throw new Error('Error deleting user');
    }
};
